package com.bank.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.bank.pojo.User;
import com.bank.utils.DbUtils;

/**
 * 银行工作人员的数据接口类
 */
public class AdminDAO {
	// 根据用户名查询管理员
	// 从数据库中获取用户信息
	public static User getLoginUser(String username) {
		String sql = "select username,password from bank_admin where username = ?";
		List param = new ArrayList<>();
		param.add(username);
		Connection connection = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			connection = DbUtils.open();
			ps = DbUtils.preparedStatement(sql, param, connection);
            if (ps != null) {
                rs = ps.executeQuery();
            }
            if (rs.next()) {
				User user = new User();
				user.setPassword(rs.getString("password"));
				user.setUsername(rs.getString("username"));
				return user;
			}
		} catch (Exception e) {
			e.printStackTrace();

		} finally {
			DbUtils.closeAll(connection, ps, null);
		}
		return null;
	}
}
